<?
use pft\Member\MemberAccount;//要放在文件的第一行位置
include '/var/www/html/new/d/common/func.inc.php';
include_once('/var/www/html/new/d/common/autoload.php');
include '/var/www/html/new/d/module/pwk/class/MemberAccount.class.php';
if(!$_SESSION['memberID']){exit("<script>window.location='dlogin.html'</script>");}
$m_info = $e_info = array();
//传值match数组
$n_arr=array("action","tt","callback");
$m_arr=array("dname","cname","dname","mobile","qq","ctel","alipay","n_accept","smstype","address");
$e_arr=array("position","sex","email","com_name","fax","website","business");
foreach($_REQUEST as $k=>$v){
    if(!is_array($v)){
    $v=safetxt($v);
    if(in_array($k,$m_arr)){
        $m_info[$k]=$v;
    }elseif(in_array($k,$e_arr)){
        $e_info[$k]=$v;
    }elseif(in_array($k,$n_arr)){
        $n_info[$k]=$v;
    }
    }
}
$n_info['id']=$_SESSION['memberID'];
if(isset($_REQUEST["com_type"])){
    $e_info['com_type']=$_REQUEST["com_type"]?implode(",",$_REQUEST["com_type"]):"";
}
if(isset($_REQUEST["d_province"])){$e_info['province']=$_REQUEST["d_province"];}
if(isset($_REQUEST["d_city"])){$e_info['city']=$_REQUEST["d_city"];}
if(isset($_REQUEST["short_company_name"])){
    $e_info['short_company_name']=$_REQUEST["short_company_name"]=="最多4个字"?"":$_REQUEST["short_company_name"];
}
$mem=new MemberAccount($GLOBALS['le']);
switch($n_info['action']){
    case 'UploadImage':
        $json='{"status":"test"}';
        echo '<script>window.parent.' . $n_info['callback'] . '('.$json.');</script>';
        exit;
        if ($_FILES[$n_info['tt']]['size']>0) {
            include '/var/www/html/new/d/module/pwk/class/Uploader.class.php';
            $account=$_SESSION['account'];
            $config = array(
            'simpleFolder'=>true,
            "savePath" => '/var/www/html/new/d/upload/'.$account.'/certifi',
            "maxSize" => 2048, //单位KB
            "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp"),
            );
            $up = new Uploader($n_info['tt'], $config);
            $info = $up->getFileInfo();
            $path='upload/'.$account.'/certifi/'.$info['name'];
            if($n_info['tt']=="headphoto"){$m_info[$n_info['tt']]='/'.$path;}
            else {$e_info[$n_info['tt']]='/'.$path;}
            $e_info['certi_status']=1;
            $e_info['apply_time']=date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']);
            $res=$mem->update($n_info['id'], $m_info, $e_info);
            if ($info['state']=='SUCCESS'&&$res['status']=="ok") {
                if(isset($_REQUEST["dname"]) && $n_info['id']==$_SESSION['memberID']){$_SESSION['dname']=$_REQUEST["dname"];}
                $json = '{"status":"ok", "key":"http://www.12301.cc/upload/'.$account.'/certifi/'.$info['name'].'"}';
            } else {
            $json = '{"status":"fail"}';
            }
            echo '<script>window.parent.' . $n_info['callback'] . '('.$json.');</script>';
        }
        break;
    case 'audit_list':
        $params['certi_status']=1;
        $params['limit']=0;
        $params['offset']=100;
        //获取详细页面信息
        $audit_list=$mem->getMemList($params,false);
        //获取总数
        $audit_list=$mem->getMemList($params,true);
        $json=json_encode($audit_list);
        var_dump($json);
        echo '<script>window.parent.ImgUpload.onload('.$json.');</script>';
        break;
    case 'enterprise':
        $res=$mem->update($n_info['id'], $m_info, $e_info);
        if ($res['status']=="ok") {
            if(isset($_REQUEST["dname"]) && $n_info['id']==$_SESSION['memberID']){$_SESSION['dname']=$m_arr["dname"];}
            $json = '{"status":"ok"}';
        } else {
            $json = '{"status":"fail"}';
        }
        echo '<script>window.parent.ImgUpload.onload('.$json.');</script>';
    case 'home_ct_st':
        $audit_one=$mem->GetOne($n_info['id']);
        echo $audit_one['certi_status'];
        break;
    default:
        break;
}
/* 其他信息更改页面的处理语句，暂不处理，待重写
$money  = safetxt((float)$_REQUEST["money"]);

    if(isset($_REQUEST["dname"])){$m_info['dname']=$_REQUEST["dname"];}
    if(isset($_REQUEST["cname"])){$m_info['cname']=$_REQUEST["cname"];}
    if(isset($_REQUEST["mobile"])){$m_info['mobile']=$_REQUEST["mobile"];}
    if(isset($_REQUEST["qq"])){
        $m_info['qq']=$_REQUEST["qq"];
        if(!$m_info['qq']){
            echo "<script>alert(\"请填写QQ,方便联系。\");</script>";
            exit;
        }
    }
    if(isset($_REQUEST["ctel"])){$m_info['ctel']=$_REQUEST["ctel"];}
    if(isset($_REQUEST["alipay"])){$m_info['alipay']=$_REQUEST["alipay"];}
    if(isset($_REQUEST["n_accept"])){$m_info['n_accept']=$_REQUEST["n_accept"];}
    if(isset($_REQUEST["smsauto"])){$m_info['smsauto']=$_REQUEST["smsauto"];}
    if(isset($_REQUEST["smstype"])){$m_info['smstype']=$_REQUEST["smstype"];}
    if(isset($_REQUEST["address"])){$m_info['address']=$_REQUEST["address"];}
    if(isset($_REQUEST["position"])){$e_info['position']=$_REQUEST["position"];}
    if(isset($_REQUEST["sex"])){$e_info['sex']=$_REQUEST["sex"];}
    if(isset($_REQUEST["email"])){$e_info['email']=$_REQUEST["email"];}
    if(isset($_REQUEST["com_name"])){$e_info['com_name']=$_REQUEST["com_name"];}
    if(isset($_REQUEST["com_type"])){
        $e_info['com_type']=$_REQUEST["com_type"]?implode(",",$_REQUEST["com_type"]):"";
    }
    if(isset($_REQUEST["d_province"])){$e_info['province']=$_REQUEST["d_province"];}
    if(isset($_REQUEST["d_city"])){$e_info['city']=$_REQUEST["d_city"];}
    if(isset($_REQUEST["fax"])){$e_info['fax']=$_REQUEST["fax"];}
    if(isset($_REQUEST["website"])) {
        $e_info['website']=$_REQUEST["website"];
    }
    if(isset($_REQUEST["business"])){
        $e_info['business']=$_REQUEST["business"];
    }

    if(isset($_REQUEST["bsn_les"])) {$e_info['bsn_les']=$_REQUEST["bsn_les"];}
    if(isset($_REQUEST["orga_les"])) {$e_info['orga_les']=$_REQUEST["orga_les"];}
    if(isset($_REQUEST["tax_les"])) {$e_info['tax_les']=$_REQUEST["tax_les"];}
    if(isset($_REQUEST["opt_les"])) {$e_info['opt_les']=$_REQUEST["opt_les"];}
    if(isset($_REQUEST["auth_les"])) {$e_info['auth_les']=$_REQUEST["auth_les"];}
    if(isset($_REQUEST["id_card_hand"])){$e_info['id_card_hand']=$_REQUEST["id_card_hand"];}
    if(isset($_REQUEST["id_card"])){$e_info['id_card']=$_REQUEST["id_card"];}
    if(isset($_REQUEST["id_card_B"])){$e_info['id_card_B']=$_REQUEST["id_card_B"];}
    if(isset($_REQUEST["other_les"])){$e_info['other_les']=$_REQUEST["other_les"];}

    if(isset($_REQUEST["short_company_name"])){
        $e_info['short_company_name']=$_REQUEST["short_company_name"]=="最多4个字"?"":$_REQUEST["short_company_name"];
    }
    if ($tt){
        $logo=$_FILES[$tt];
    }*/
/*$finfo = new finfo(FILEINFO_MIME);
            $a=$finfo->file('/var/www/html/new/d/'.$path);
            var_dump($a);*/
/*
if($money!=0){
    if(($res=$s->PFT_Member_Fund_Modify((int)$_SESSION['memberID'],(int)$_SESSION['memberID'],(abs($money)*100),($money>0?1:0),0,"",3,0))==100){
        if(($res=$s->PFT_Member_Fund_Modify((int)$id,(int)$_SESSION['memberID'],(abs($money)*100),($money>0?0:1),0,"",3,0))!=100){
            echo "<script>alert('充值出错:".$res."');</script>";
            exit;
        }
    }
}*/
/*
if ($tt){
    $logo=$_FILES[$tt];
}
if($logo["size"]){
    $type=array("image/gif","image/jpeg","image/pjpeg","image/png","image/x-png");
    $maxsize=2000000;

    if($_SERVER['REQUEST_METHOD']=="POST"){

        if (in_array($logo["type"],$type) && ($logo["size"] < $maxsize)) {
            if ($logo["error"] > 0){
                echo $logo["error"];
            }
            else{

                $sel="select account from pft_member where id=".$_SESSION['sid']." limit 1";
                $GLOBALS['le']->query($sel);
                $GLOBALS['le']->fetch_assoc();
                $passport=$GLOBALS['le']->f("account");
                //生成存储路径
                $dir="module/pwk/upload/".$passport;
                if(!is_dir($dir)){
                    mkdir($dir);
                    chmod($dir, 0777);
                }
                if (!is_writable($dir)) {
                    @chmod($dir, 0777);
                }
                $fileinfo=pathinfo($logo["name"]);
                $filetype=$fileinfo['extension'];
                $dir.="/".$_SERVER['REQUEST_TIME'].".".$filetype;
                //截取图片
                list($width_orig, $height_orig) = getimagesize($logo["tmp_name"]);
                $star_x=0;//源的 X 坐标点
                $star_y=0;//源的 Y 坐标点
                $copy_width=$width_orig;//源图象的宽度
                $copy_height=$height_orig;//源图象的高度
                $width=$width_orig;//目标宽度
                $height=$height_orig;//目标高度

                $image_p = imagecreatetruecolor($width, $height);

                switch($logo["type"]){
                    case "image/pjpeg":
                        $image = imagecreatefromjpeg($logo["tmp_name"]);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagejpeg($image_p, $dir, 100);
                        break;
                    case "image/jpeg":
                        $image = imagecreatefromjpeg($logo["tmp_name"]);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagejpeg($image_p, $dir, 100);
                        break;
                    case "image/gif":
                        $image = imagecreatefromgif($logo["tmp_name"]);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagegif($image_p, $dir, 100);
                        break;
                    case "image/x-png":
                        $image = imagecreatefrompng($logo["tmp_name"]);
                        $alpha = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
                        imagefill($image_p, 0, 0, $alpha);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagesavealpha($image_p, true);
                        imagepng($image_p, $dir, 9);
                        break;
                    case "image/png":
                        $image = imagecreatefrompng($logo["tmp_name"]);
                        $alpha = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
                        imagefill($image_p, 0, 0, $alpha);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagesavealpha($image_p, true);
                        imagepng($image_p, $dir, 9);
                        break;
                }
                if($tt=="headphoto")$m_info[$tt]="/".$dir;
                else $e_info[$tt]="/".$dir;
                var_dump($e_info[$tt]);
            }
        }
        else{
            echo "<script>alert(\"上传文件类型不合法或过大!\");</script>";
            exit;
        }
    }
    else{
        echo "<script>alert(\"传输类型非POST!\");</script>";
        exit;
    }
}*/

/*
use pft\Member\MemberAccount;//要放在文件的第一行位置
include_once('common/autoload.php');
$money=(float)$_REQUEST["money"];
$m_info=$e_info=array();
if(isset($_REQUEST["dname"])){$m_info['dname']=$_REQUEST["dname"];}
if(isset($_REQUEST["cname"])){$m_info['cname']=$_REQUEST["cname"];}
if(isset($_REQUEST["mobile"])){$m_info['mobile']=$_REQUEST["mobile"];}
if(isset($_REQUEST["qq"])){
    $m_info['qq']=$_REQUEST["qq"];
    if(!$m_info['qq']){
        echo "<script>alert(\"请填写QQ,方便联系。\");</script>";
        exit;
    }
}
if(isset($_REQUEST["ctel"])){$m_info['ctel']=$_REQUEST["ctel"];}
if(isset($_REQUEST["alipay"])){$m_info['alipay']=$_REQUEST["alipay"];}
if(isset($_REQUEST["n_accept"])){$m_info['n_accept']=$_REQUEST["n_accept"];}
if(isset($_REQUEST["smsauto"])){$m_info['smsauto']=$_REQUEST["smsauto"];}
if(isset($_REQUEST["smstype"])){$m_info['smstype']=$_REQUEST["smstype"];}
if(isset($_REQUEST["address"])){$m_info['address']=$_REQUEST["address"];}
if(isset($_REQUEST["position"])){$e_info['position']=$_REQUEST["position"];}
if(isset($_REQUEST["sex"])){$e_info['sex']=$_REQUEST["sex"];}
if(isset($_REQUEST["email"])){$e_info['email']=$_REQUEST["email"];}
if(isset($_REQUEST["com_name"])){$e_info['com_name']=$_REQUEST["com_name"];}
if(isset($_REQUEST["com_type"])){
    $e_info['com_type']=$_REQUEST["com_type"]?implode(",",$_REQUEST["com_type"]):"";
}
if(isset($_REQUEST["d_province"])){$e_info['province']=$_REQUEST["d_province"];}
if(isset($_REQUEST["d_city"])){$e_info['city']=$_REQUEST["d_city"];}
if(isset($_REQUEST["fax"])){$e_info['fax']=$_REQUEST["fax"];}
if(isset($_REQUEST["website"])) {
    $e_info['website']=$_REQUEST["website"];
}
if(isset($_REQUEST["business"])){
    $e_info['business']=$_REQUEST["business"];
}
if(isset($_REQUEST["bsn_les"])) {$e_info['bsn_les']=$_REQUEST["bsn_les"];}
if(isset($_REQUEST["opt_les"])) {$e_info['opt_les']=$_REQUEST["opt_les"];}
if(isset($_REQUEST["id_card"])){
    $e_info['id_card']=$_REQUEST["id_card"];
}
if(isset($_REQUEST["short_company_name"])){
    $e_info['short_company_name']=$_REQUEST["short_company_name"]=="最多4个字"?"":$_REQUEST["short_company_name"];
}
$tt = $_REQUEST['tt'];
if ($tt){
    $logo=$_FILES[$tt];
}

if($logo["size"]){
    $type=array("image/gif","image/jpeg","image/pjpeg","image/png","image/x-png");
    $maxsize=2000000;

    if($_SERVER['REQUEST_METHOD']=="POST"){

        if (in_array($logo["type"],$type) && ($logo["size"] < $maxsize)) {
            if ($logo["error"] > 0){
                echo $logo["error"];
            }
            else{

                $sel="select account from pft_member where id=".$_SESSION['sid']." limit 1";
                $GLOBALS['le']->query($sel);
                $GLOBALS['le']->fetch_assoc();
                $passport=$GLOBALS['le']->f("account");
                //生成存储路径
                $dir="upload/".$passport;
                if(!is_dir($dir)){
                    mkdir($dir);
                    chmod($dir, 0777);
                }
                if (!is_writable($dir)) {
                    @chmod($dir, 0777);
                }
                $fileinfo=pathinfo($logo["name"]);
                $filetype=$fileinfo['extension'];
                $dir.="/".$_SERVER['REQUEST_TIME'].".".$filetype;
                //截取图片
                list($width_orig, $height_orig) = getimagesize($logo["tmp_name"]);
                $star_x=0;//源的 X 坐标点
                $star_y=0;//源的 Y 坐标点
                $copy_width=$width_orig;//源图象的宽度
                $copy_height=$height_orig;//源图象的高度
                $width=$width_orig;//目标宽度
                $height=$height_orig;//目标高度

                $image_p = imagecreatetruecolor($width, $height);

                switch($logo["type"]){
                    case "image/pjpeg":
                        $image = imagecreatefromjpeg($logo["tmp_name"]);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagejpeg($image_p, $dir, 100);
                        break;
                    case "image/jpeg":
                        $image = imagecreatefromjpeg($logo["tmp_name"]);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagejpeg($image_p, $dir, 100);
                        break;
                    case "image/gif":
                        $image = imagecreatefromgif($logo["tmp_name"]);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagegif($image_p, $dir, 100);
                        break;
                    case "image/x-png":
                        $image = imagecreatefrompng($logo["tmp_name"]);
                        $alpha = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
                        imagefill($image_p, 0, 0, $alpha);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagesavealpha($image_p, true);
                        imagepng($image_p, $dir, 9);
                        break;
                    case "image/png":
                        $image = imagecreatefrompng($logo["tmp_name"]);
                        $alpha = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
                        imagefill($image_p, 0, 0, $alpha);
                        imagecopyresampled($image_p, $image, 0, 0, $star_x, $star_y, $width, $height, $copy_width, $copy_height);
                        imagesavealpha($image_p, true);
                        imagepng($image_p, $dir, 9);
                        break;
                }
                if($tt=="headphoto")$m_info[$tt]="/".$dir;
                else $e_info[$tt]="/".$dir;
            }
        }
        else{
            echo "<script>alert(\"上传文件类型不合法或过大!\");</script>";
            exit;
        }
    }
    else{
        echo "<script>alert(\"传输类型非POST!\");</script>";
        exit;
    }
}
if($money!=0){
    if(($res=$s->PFT_Member_Fund_Modify((int)$_SESSION['memberID'],(int)$_SESSION['memberID'],(abs($money)*100),($money>0?1:0),0,"",3,0))==100){
        if(($res=$s->PFT_Member_Fund_Modify((int)$id,(int)$_SESSION['memberID'],(abs($money)*100),($money>0?0:1),0,"",3,0))!=100){
            echo "<script>alert('充值出错:".$res."');</script>";
            exit;
        }
    }
}
$mem = new MemberAccount($GLOBALS['le']);//实例化时需要注入mysql连接标识
$res=$mem->update($id, $m_info, $e_info);
if($res['status']=="ok"){
    if(isset($_REQUEST["dname"]) && $id==$_SESSION['memberID']){$_SESSION['dname']=$_REQUEST["dname"];}
    echo "<script>alert('修改成功!');parent.window.location=window.parent.location.href;</script>";
    exit;
}
else{
    echo "<script>alert(\"".$res['msg']."\")</script>";
}
*/
?>